home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_hylafax.idb / usr / freeware / var / httpd / cgi-bin / manpage.z / manpage
Encoding:
Korn shell script  |  1999-07-16  |  4.8 KB  |  129 lines

  1. #!/bin/ksh
  2. #    $Id: manpage.sh.in,v 1.20 1996/06/24 03:03:40 sam Rel $
  3. #
  4. # Copyright (c) 1994-1995 Sam Leffler
  5. # Copyright (c) 1994-1995 Silicon Graphics, Inc.
  6. # Permission to use, copy, modify, distribute, and sell this software and 
  7. # its documentation for any purpose is hereby granted without fee, provided
  8. # that (i) the above copyright notices and this permission notice appear in
  9. # all copies of the software and related documentation, and (ii) the names of
  10. # Sam Leffler and Silicon Graphics may not be used in any advertising or
  11. # publicity relating to the software without the specific, prior written
  12. # permission of Sam Leffler and Silicon Graphics.
  13. # THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  14. # EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  15. # WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  16. # IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  17. # ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  18. # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. # WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  20. # LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  21. # OF THIS SOFTWARE.
  22. #
  23.  
  24. #
  25. # manpage?query
  26. #
  27. # Retrieve a UNIX manual page using man and return an HTML
  28. # document with the appropriate font changes and anchors
  29. # (for other manual page references).  Other stuff like page
  30. # headers and footers are left, though they could trivially
  31. # be removed with more sed commands.  Likewise one can add
  32. # other anchors such as include file references.
  33. #
  34. # Note that only a single manual page (the first hit) is
  35. # returned.  This is not a general purpose manual interface;
  36. # it's intended for linking manual pages to HTML documents.
  37. #
  38. # NB: man is much faster if invoked with a section; it's best
  39. #     to use "manpage?section+query" instead of "manpage?query"
  40. #
  41. PATH=/bin:/usr/bin
  42. test -d /usr/sbin && PATH=$PATH:/usr/sbin        # SGI and others
  43. test -d /usr/bsd && PATH=$PATH:/usr/bsd            # SGI
  44. test -d /usr/ucb && PATH=$PATH:/usr/ucb            # Sun and others
  45. test -d /usr/5bin && PATH=/usr/5bin:$PATH        # Sun and others
  46. test -d /usr/local/bin && PATH=/usr/local/bin:$PATH    # for GNU stuff
  47.  
  48. ECHO=/bin/echo
  49. SED=/bin/sed
  50. CAT=/bin/cat
  51. MAN=/bin/man
  52. COL=/bin/col
  53. MAN2HTML=/var/httpd/cgi-bin/man2html
  54.  
  55. case "mips-sgi-irix6.5-ALPHA-1275645130" in
  56. *-irix*)    MAN_FLAGS="-p -c" ;;
  57. *)        MAN_FLAGS="" ;;
  58. esac
  59.  
  60. #
  61. # XXX the server expands the pathname when
  62. # setting SCRIPT_NAME, so it can't be reused.
  63. #
  64. SCRIPT_NAME=/cgi-bin/manpage
  65. UNQUOTE=/var/httpd/cgi-bin/unquote
  66.  
  67. MANPATH=/usr/freeware/man:/usr/share/catman:/usr/share/man:/usr/catman:/usr/man
  68. export MANPATH
  69.  
  70. $ECHO 'Content-type: text/html'
  71. $ECHO ''
  72.  
  73. cvtLinks()
  74. {
  75.     #
  76.     # The first two expressions skip correctly formatted page headers
  77.     # (NB: many man pages are incorrectly formatted).  The 3rd
  78.     # expression handles the normal man page reference.  The
  79.     # last 3 expressions deal with incorrectly formatted references.
  80.     #
  81.     $SED -e "/^ *[A-Z][A-Z_0-9]*([l-p1-8][a-zA-Z]*)/n" \
  82.     -e "/^ *<B> *[A-Z][A-Z_0-9]*([l-p1-8][a-zA-Z]*)/n" \
  83.     -e "s;<[IB]>\([^<]*\)</[IB]>(\([l-p1-8]\)\([a-zA-Z]\{0,1\}\));<A HREF=\"$SCRIPT_NAME?\2+\1\">\1(\2\3)</A>;g" \
  84.     -e "s;<[IB]>\([^<]*\)</[IB]>(<[IB]>\([l-p1-8]\)\([a-zA-Z]\{0,1\}\)</[IB]>);<A HREF=\"$SCRIPT_NAME?\2+\1\">\1(\2\3)</A>;g" \
  85.     -e "s;<[IB]><[IB]>\([^<]*\)</[IB]></[IB]>(\([l-p1-8]\)\([a-zA-Z]\{0,1\}\));<A HREF=\"$SCRIPT_NAME?\2+\1\">\1(\2\3)</A>;g" \
  86.     -e "s;\([a-zA-Z_0-9][a-zA-Z_0-9]*\)(\([l-p1-8]\)\([a-zA-Z]\{0,1\}\));<A HREF=\"$SCRIPT_NAME?\2+\1\">\1(\2\3)</A>;g"
  87. }
  88.  
  89. QUERY=`$ECHO "$QUERY_STRING" | $UNQUOTE -qn`
  90.  
  91. $CAT<<EOF
  92. <TITLE>UNIX Manual Page: man $QUERY</TITLE>
  93.  
  94. <BODY>
  95. EOF
  96.  
  97. if [ -x $MAN -a -x $COL -a -x $MAN2HTML ]; then
  98.     CMD=`$MAN $MAN_FLAGS $QUERY | $SED 1q`
  99.     case "$CMD" in
  100.     *[nN]o*manual*)
  101.     echo "<H2><IMG SRC=\"/hylafax/icons/button.excl.gif\">$CMD</H2>"
  102.     echo 'The <KBD>man</KBD> command did not locate the requested manual'
  103.     echo 'page.  This is typically because the file is not present on the'
  104.     echo 'machine, but it can also be caused by a mistyped query string'
  105.     echo 'or some resource (e.g. an NFS-mounted filesystem) being'
  106.     echo 'temporarily unavailable.'
  107.     ;;
  108.     *)
  109.     echo '<PRE WIDTH=80>'
  110.     $MAN $MAN_FLAGS $QUERY 2>/dev/null | $COL -x | $MAN2HTML | cvtLinks
  111.     echo '</PRE>'
  112.     ;;
  113.     esac
  114. else
  115.     echo '<H2><IMG SRC="/hylafax/icons/button.excl.gif">No manual page support</H2>'
  116.     echo 'All the programs required to support manual page queries were'
  117.     echo 'not available or were not in the expected locations.  The following'
  118.     echo 'programs are required:'
  119.     echo '<PRE>'
  120.     echo "$MAN    standard manual page program"
  121.     echo "$COL    to filter reverse-line feeds"
  122.     echo "$MAN2HTML    to convert the output of $MAN to HTML"
  123.     echo '</PRE><P>'
  124. fi
  125. echo '</BODY>'
  126.